package com.example;

import org.apache.camel.RoutesBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.spi.Resource;
import org.apache.camel.spi.RoutesBuilderLoader;
import org.apache.camel.support.ResourceHelper;

/**
 * @author koyou
 * @version 1.0.0
 * @className YamlLoaderRouteBuilder
 * @description yaml dsl
 * @since 2025/6/12 11:15
 */
public class YamlLoaderRouteBuilder extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        Resource yamlResource = ResourceHelper.resolveResource(getContext(), "classpath:routes/my-route.yaml");
        RoutesBuilderLoader loader = getContext().getRegistry().findSingleByType(RoutesBuilderLoader.class);
        if (loader == null) {
            throw new IllegalStateException("No RoutesBuilderLoader registered in CamelContext");
        }
        RoutesBuilder yamlBuilder = loader.loadRoutesBuilder(yamlResource);
        getContext().addRoutes(yamlBuilder);
    }

}
